import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router) 

const home = () => import('../views/navBar/home/home.vue')
const category = () => import('../views/navBar/category/category')
const cart = () => import('../views/navBar/cart/cart')
const profile = () => import('../views/navBar/profile/profile')
const detail = ()=> import('views/navBar/detail/detail')
const routes = [
    {
      path:'',
      redirect:'/home',
			meta:{
				title:'主页'
			}
    },
    {
      path:'/home',
      component:home,
			meta:{
				title:'主页'
			}
    },
    {
      path:'/category', 
      component:category,
			meta:{
				title:'分类'
			}
    },
    {
      path:'/cart', 
      component:cart,
			meta:{
				title:'购物车'
			}
    },
    {
      path:'/profile',
      component:profile,
			meta:{
				title:'我的'
			}
    },
		{
		  path:'/detail',
		  component:detail,
			meta:{
				title:'详情页'
			}
		},
  ]

const router = new Router({
  routes,
  mode:'history'
})
//路由跳转之前将文档的标题修改为对应的标题
router.beforeEach( (to,from,next) => {
	document.title = to.matched[0].meta.title;
	next()
})
const VueRouterPush = Router.prototype.push;
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}


export default router